<html>
<head><meta charset="utf-8"><title>What is the public type of `mir::_::Predecessor`? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html">What is the public type of `mir::_::Predecessor`?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216716453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216716453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216716453">(Nov 14 2020 at 08:46)</a>:</h4>
<p>I want, for all argument of a function call to know if the argument was created only locally or from the argument of this function.</p>
<div class="spoiler-block"><div class="spoiler-header">
<p>examples</p>
</div><div class="spoiler-content" aria-hidden="true">
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">arg1</span><span class="p">(</span><span class="n">i</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">callee</span><span class="p">(</span><span class="n">i</span><span class="p">);</span><span class="w"> </span><span class="c1">// from arguments</span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">arg2</span><span class="p">(</span><span class="n">i</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">3</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">callee</span><span class="p">(</span><span class="n">j</span><span class="p">);</span><span class="w"> </span><span class="c1">// from arguments</span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">local1</span><span class="p">(</span><span class="n">_i</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="n">callee</span><span class="p">(</span><span class="mi">3</span><span class="p">);</span><span class="w"> </span><span class="c1">// from locals only</span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">local2</span><span class="p">(</span><span class="n">_i</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">callee</span><span class="p">(</span><span class="mi">4</span><span class="p">);</span><span class="w"> </span><span class="c1">// from locals only</span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">arg3</span><span class="p">(</span><span class="n">i</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">random</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">i</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="mi">4</span><span class="w"></span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>
<span class="w">    </span><span class="n">callee</span><span class="p">(</span><span class="n">j</span><span class="p">);</span><span class="w"> </span><span class="c1">// from arguments</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
</div></div>
<p>I'm doing this analysis using mir. I think I have nearly everything that I need.</p>
<ul>
<li>I created a type <code>SearchFunctionCall</code> that implements the visitor pattern, more specifically overwrite the <code>visit_terminator()</code> function to visit all function block.</li>
<li>I can access to the arguments list with <code>if let TerminatorKind::Call{func, args, ..} = &amp;terminator.kind</code><br>
Now, I just need to be able to track the source of each <code>arg</code> backward, and I assume that <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/predecessors/type.Predecessors.html"><code>Predecessor</code></a> is exactly what I want. I'm using <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html#method.predecessors"><code>Body::predecessors()</code></a> to create it.</li>
</ul>
<p>The only issue: <code>Predecessors</code> is <strong>not</strong> a public type, so I can't name the type of the value returned by <code>Body::predecessors()</code>. Any idea on how to move forward?</p>



<a name="216716711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216716711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216716711">(Nov 14 2020 at 08:51)</a>:</h4>
<p>is there a reason you need to name it?</p>



<a name="216717280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216717280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216717280">(Nov 14 2020 at 09:05)</a>:</h4>
<p>Either I pass the mir borrow into my <code>SearchFunctionCall</code> object, and then re-create it each time I'm into the <code>visit_terminator()</code> function, or I could just store a reference to the <code>Predecessors</code> object in my <code>SearchFunctionCall</code>.</p>
<div class="spoiler-block"><div class="spoiler-header">
</div><div class="spoiler-content" aria-hidden="true">
<p>Passing a reference to MIR </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w"> </span><span class="k">struct</span> <span class="nc">SearchFunctionCall</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">inner_functions</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">Operand</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">mir</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">tcx</span> <span class="nc">rustc_data_structures</span>::<span class="n">sync</span>::<span class="n">MappedReadGuard</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="p">,</span><span class="w"> </span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">Body</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="n">SearchFunctionCall</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">mir</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">tcx</span> <span class="nc">rustc_data_structures</span>::<span class="n">sync</span>::<span class="n">MappedReadGuard</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="p">,</span><span class="w"> </span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">Body</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">SearchFunctionCall</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">inner_functions</span>: <span class="nb">Vec</span>::<span class="n">new</span><span class="p">(),</span><span class="w"></span>
<span class="w">            </span><span class="n">mir</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">use</span><span class="w"> </span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">terminator</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">Location</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">visit</span>::<span class="n">Visitor</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">SearchFunctionCall</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">visit_terminator</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">terminator</span>: <span class="kp">&amp;</span><span class="nc">Terminator</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">_location</span>: <span class="nc">Location</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">predecessors</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">mir</span><span class="p">.</span><span class="n">predecessors</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">TerminatorKind</span>::<span class="n">Call</span><span class="p">{</span><span class="n">func</span><span class="p">,</span><span class="w"> </span><span class="n">args</span><span class="p">,</span><span class="w"> </span><span class="o">..</span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">terminator</span><span class="p">.</span><span class="n">kind</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="c1">// do something with predecessors and arg</span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>versus storing the predecessor</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w"> </span><span class="k">struct</span> <span class="nc">SearchFunctionCall</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">inner_functions</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">Operand</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">predecessors</span>: <span class="o">???</span><span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="n">SearchFunctionCall</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">predecessor</span>: <span class="o">???</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">SearchFunctionCall</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">inner_functions</span>: <span class="nb">Vec</span>::<span class="n">new</span><span class="p">(),</span><span class="w"></span>
<span class="w">            </span><span class="n">mir</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">use</span><span class="w"> </span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">terminator</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">Location</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="n">rustc_middle</span>::<span class="n">mir</span>::<span class="n">visit</span>::<span class="n">Visitor</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">SearchFunctionCall</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">visit_terminator</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">terminator</span>: <span class="kp">&amp;</span><span class="nc">Terminator</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">_location</span>: <span class="nc">Location</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">TerminatorKind</span>::<span class="n">Call</span><span class="p">{</span><span class="n">func</span><span class="p">,</span><span class="w"> </span><span class="n">args</span><span class="p">,</span><span class="w"> </span><span class="o">..</span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">terminator</span><span class="p">.</span><span class="n">kind</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="c1">// do something with self.predecessors and args</span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
</div></div>
<div class="codehilite"><pre><span></span><code>
</code></pre></div>



<a name="216717381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216717381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216717381">(Nov 14 2020 at 09:08)</a>:</h4>
<p>sounds like you need <code>type_alias_impl_trait</code></p>



<a name="216717383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216717383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216717383">(Nov 14 2020 at 09:08)</a>:</h4>
<p>rustdoc uses nightly already, don't worry</p>



<a name="216718042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216718042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216718042">(Nov 14 2020 at 09:27)</a>:</h4>
<p>I may not have understood what the type <code>Predecessor</code> is. Given the following extract of the mir for my <code>indirect</code> function:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">indirect</span><span class="p">(</span><span class="n">_1</span>: <span class="nc">Fct</span><span class="p">,</span><span class="w"> </span><span class="n">_2</span>: <span class="kt">isize</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">debug</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">_1</span><span class="p">;</span><span class="w">                     </span><span class="c1">// in scope 0 at src/lib.rs:5:29: 5:32</span>
<span class="w">    </span><span class="n">debug</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">_2</span><span class="p">;</span><span class="w">                       </span><span class="c1">// in scope 0 at src/lib.rs:5:39: 5:40</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">_0</span>: <span class="p">();</span><span class="w">                      </span><span class="c1">// return place in scope 0 at src/lib.rs:5:49: 5:49</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_3</span>: <span class="p">();</span><span class="w">                          </span><span class="c1">// in scope 0 at src/lib.rs:6:5: 6:11</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">_4</span>: <span class="kp">&amp;</span><span class="nc">Fct</span><span class="p">;</span><span class="w">                    </span><span class="c1">// in scope 0 at src/lib.rs:6:5: 6:8</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">_5</span>: <span class="p">(</span><span class="kt">isize</span><span class="p">,);</span><span class="w">                </span><span class="c1">// in scope 0 at src/lib.rs:6:5: 6:11</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">_6</span>: <span class="kt">isize</span><span class="p">;</span><span class="w">                   </span><span class="c1">// in scope 0 at src/lib.rs:6:9: 6:10</span>

<span class="w">    </span><span class="n">bb0</span>: <span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">StorageLive</span><span class="p">(</span><span class="n">_3</span><span class="p">);</span><span class="w">                 </span><span class="c1">// scope 0 at src/lib.rs:6:5: 6:11</span>
<span class="w">        </span><span class="n">StorageLive</span><span class="p">(</span><span class="n">_4</span><span class="p">);</span><span class="w">                 </span><span class="c1">// scope 0 at src/lib.rs:6:5: 6:8</span>
<span class="w">        </span><span class="n">_4</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">_1</span><span class="p">;</span><span class="w">                        </span><span class="c1">// scope 0 at src/lib.rs:6:5: 6:8</span>
<span class="w">        </span><span class="n">StorageLive</span><span class="p">(</span><span class="n">_5</span><span class="p">);</span><span class="w">                 </span><span class="c1">// scope 0 at src/lib.rs:6:5: 6:11</span>
<span class="w">        </span><span class="n">StorageLive</span><span class="p">(</span><span class="n">_6</span><span class="p">);</span><span class="w">                 </span><span class="c1">// scope 0 at src/lib.rs:6:9: 6:10</span>
<span class="w">        </span><span class="n">_6</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">_2</span><span class="p">;</span><span class="w">                         </span><span class="c1">// scope 0 at src/lib.rs:6:9: 6:10</span>
<span class="w">        </span><span class="p">(</span><span class="n">_5</span><span class="p">.</span><span class="mi">0</span>: <span class="kt">isize</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">move</span><span class="w"> </span><span class="n">_6</span><span class="p">;</span><span class="w">         </span><span class="c1">// scope 0 at src/lib.rs:6:5: 6:11</span>
<span class="w">        </span><span class="n">_3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&lt;</span><span class="n">Fct</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nb">Fn</span><span class="o">&lt;</span><span class="p">(</span><span class="kt">isize</span><span class="p">,)</span><span class="o">&gt;&gt;</span>::<span class="n">call</span><span class="p">(</span><span class="k">move</span><span class="w"> </span><span class="n">_4</span><span class="p">,</span><span class="w"> </span><span class="k">move</span><span class="w"> </span><span class="n">_5</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="k">return</span>: <span class="nc">bb1</span><span class="p">,</span><span class="w"> </span><span class="n">unwind</span>: <span class="nc">bb3</span><span class="p">];</span><span class="w"> </span><span class="c1">// scope 0 at src/lib.rs:6:5: 6:11</span>
<span class="w">                                         </span><span class="c1">// mir::Constant</span>
<span class="w">                                         </span><span class="c1">// + span: src/lib.rs:6:5: 6:8</span>
<span class="w">                                         </span><span class="c1">// + literal: Const { ty: for&lt;'r&gt; extern "rust-call" fn(&amp;'r Fct, (isize,)) -&gt; &lt;Fct as std::ops::FnOnce&lt;(isize,)&gt;&gt;::Output {&lt;Fct as std::ops::Fn&lt;(isize,)&gt;&gt;::call}, val: Value(Scalar(&lt;ZST&gt;)) }</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>The arguments to the function call are respectively <code>move _4</code> and <code>move _5</code>. I want to go back to the original source of those variable. Here <code>_4</code> was created from <code>_1</code> and <code>_5</code> from <code>_6</code>. I can apply that algorithm respectively for <code>_6</code> which gives <code>_2</code>. In this case both <code>_4</code> and <code>_5</code> were creating from the argument of the function. If it wasn't the case, then all the source would have been a <code>mir::Constant</code> (you can have multiple source if there is some constructions, like a <code>if</code>).</p>
<p>I thought that the <code>Predecessors</code> would give me exactly that information. Am I wrong?</p>



<a name="216718245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216718245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216718245">(Nov 14 2020 at 09:32)</a>:</h4>
<p>Maybe, the way I'm doing it is stupid, I though I could do:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">arg</span><span class="w"></span>
<span class="w">    </span><span class="p">.</span><span class="n">place</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="w"></span>
<span class="w">        </span><span class="o">|</span><span class="n">p</span><span class="o">|</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">local_or_deref_local</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="n">l</span><span class="o">|</span><span class="w"> </span><span class="n">l</span><span class="p">.</span><span class="n">index</span><span class="p">()))</span><span class="w"></span>
</code></pre></div>
<p>If I get a <code>None</code> it's because it's a local variable. Then I used that index to create a <code>BasicBlock</code>: <code>rustc_middle::mir::BasicBlock::from_usize(l.index())</code>, and finally index into the precedessors: <code>&amp;predecessors[basic_block])</code>.</p>
<p>But I'm not sure at all if the index of the place is what I should use to create a basic block.</p>



<a name="216718402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216718402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216718402">(Nov 14 2020 at 09:35)</a>:</h4>
<p>Said otherwise, is my approach right (starting from the function call, then moving backward until I find the source of the variables (either local or from arguments)). Or should I do it the other way, (ie moving forward from the arguments), and setting a boolean for every mir variable that can be reached from the arguments (ie. all variables whose boolean isn't set was created only from local variables, while any variable that whose boolean was set was created (at least indirectly) from the arguments).</p>



<a name="216718524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/What%20is%20the%20public%20type%20of%20%60mir%3A%3A_%3A%3APredecessor%60%3F/near/216718524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/What.20is.20the.20public.20type.20of.20.60mir.3A.3A_.3A.3APredecessor.60.3F.html#216718524">(Nov 14 2020 at 09:37)</a>:</h4>
<p>I will try this second approach, and see what I get from it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>